#include "com_voe_VoENetEqStats.h"
#include "jni_api.h"
#include "OutputParam.h"
#include "common_types.h"
#include "voe_neteq_stats.h"

/*
 * Class:     com_voe_VoENetEqStats
 * Method:    GetInterface
 * Signature: (J)J
 */
JNIEXPORT jlong JNICALL Java_com_voe_VoENetEqStats_GetInterface
	(JNIEnv* env, jclass cls, jlong p_voiceEngine)
{
	return (jlong)webrtc::VoENetEqStats::GetInterface((webrtc::VoiceEngine*)p_voiceEngine);
}

/*
 * Class:     com_voe_VoENetEqStats
 * Method:    Release
 * Signature: (J)I
 */
JNIEXPORT jint JNICALL Java_com_voe_VoENetEqStats_Release
	(JNIEnv* env, jclass cls, jlong p)
{
	webrtc::VoENetEqStats* pVoENetEqStats = (webrtc::VoENetEqStats*)p;
	return pVoENetEqStats->Release();
}

/*
 * Class:     com_voe_VoENetEqStats
 * Method:    GetNetworkStatistics
 * Signature: (JILcom/voe/common/OutputParam;)I
 */
JNIEXPORT jint JNICALL Java_com_voe_VoENetEqStats_GetNetworkStatistics
	(JNIEnv* env, jclass cls, jlong p, jint channel, jobject obj)
{
	webrtc::VoENetEqStats* pVoENetEqStats = (webrtc::VoENetEqStats*)p;
	webrtc::NetworkStatistics stats = {0};
	jint result = pVoENetEqStats->GetNetworkStatistics(channel, stats);
	if(result == 0)
	{
		JniOutputBuilder job(env);
		OutputParam param(env, obj);
		param.setArray(job
			.add((int)stats.currentBufferSize)
			.add((int)stats.preferredBufferSize)
			.add((bool)stats.jitterPeaksFound)
			.add((int)stats.currentPacketLossRate)
			.add((int)stats.currentDiscardRate)
			.add((int)stats.currentExpandRate)
			.add((int)stats.currentPreemptiveRate)
			.add((int)stats.currentAccelerateRate)
			.add((int)stats.clockDriftPPM)
			.add((int)stats.meanWaitingTimeMs)
			.add((int)stats.medianWaitingTimeMs)
			.add((int)stats.minWaitingTimeMs)
			.add((int)stats.maxWaitingTimeMs)
			.add((int)stats.addedSamples)
			.getOutput());
	}
	return result;
}

